/***********************************************************************

 Copyright (c) 2009, Luke Malcolm, www.lukemalcolm.com
 Based on ofxFileStream by Todd Vanderlin, www.vanderlin.cc

 This program is free software: you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation, either version 3 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program.  If not, see <http://www.gnu.org/licenses/>.

 ***********************************************************************/

#pragma once
#include "ofMain.h"
#include "ofxDirList.h"
#include "ofxTimer.h"
#include "ofxSMSEvent.h"
#include "ofxSMSMessage.h"
#include "uuid/uuid.h"

class ofxSMS : public ofxDirList {

private:

	string				debugText;
	string				inboxPath;
	string              outboxPath;
	vector <string>		files;
	int				    fileIDCount;
	ofxTimer			timer;
	bool				bSearching;
	bool				bVerbose;


public:

	int				            numFiles;
	bool				        bAllocated;
	ofEvent <ofxSMSEventArgs>	NEW_SMS;

	vector <ofxSMSMessage>      all;
    vector <ofxSMSMessage>      read;
    vector <ofxSMSMessage>      unread;

	bool                        bMoveFiles;

	// ---------------------------------------
	ofxSMS();
	~ofxSMS();

	// ---------------------------------------
	void setup(string path, float seconds);
	void setTimer(float seconds);
	void draw(float x, float y);
	void newSMSEvent(ofxSMSEventArgs &e);


	int             getUnreadN();
	bool            bUnreadSMS();
	ofxSMSMessage   getNextUnreadSMS();
	ofxSMSMessage   getSMS(string id);
	bool            send(string toNumber, string message);



	// ---------------------------------------
	void setPath(string p);


protected:

    void _processSMSFile(int id, string name, string path);
    void _checkForNewFiles(ofEventArgs &e);

    bool _fileExists(string strFilename);
    void _updateReadFlags();
    bool _sendToSpoolDir(ofxSMSMessage outSMS);

};
